package com.jie.langlangmall.controller;

import com.jie.langlangmall.common.api.CommonResult;
import com.jie.langlangmall.dto.SmsFlashPromotionSessionDetail;
import com.jie.langlangmall.model.SmsFlashPromotionSession;
import com.jie.langlangmall.service.SmsFlashPromotionSessionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author Jie
 * @Date 2024/11/26
 * @Email 3217998214@qq.com
 * @Description 限时活动、秒杀场次
 */
@RestController
@Tag(name = "SmsFlashPromotionSessionController", description = "限时购场次管理")
@RequestMapping("/flashSession")
public class SmsFlashPromotionSessionController {

    @Autowired
    private SmsFlashPromotionSessionService flashPromotionSessionService;

    @Operation(summary = "添加场次")
    @PostMapping("/create")
    public CommonResult<?> create(@RequestBody SmsFlashPromotionSession promotionSession) {
        flashPromotionSessionService.create(promotionSession);
        return CommonResult.success();
    }

    @Operation(summary = "更新场次")
    @PostMapping("/update/{id}")
    public CommonResult<?> update(@PathVariable Long id, @RequestBody SmsFlashPromotionSession promotionSession) {
        flashPromotionSessionService.update(id, promotionSession);
        return CommonResult.success();
    }

    @Operation(summary = "修改启动状态")
    @PostMapping("/update/status/{id}")
    public CommonResult<?> updateStatus(@PathVariable("id") Long id, Integer status) {
        flashPromotionSessionService.updateStatus(id, status);
        return CommonResult.success();
    }

    @Operation(summary = "删除场次")
    @PostMapping("/delete/{id}")
    public CommonResult<?> delete(@PathVariable Long id) {
        flashPromotionSessionService.delete(id);
        return CommonResult.success();
    }

    @Operation(summary = "获取详情")
    @GetMapping("/{id}")
    public CommonResult<SmsFlashPromotionSession> detail(@PathVariable("id") Long id) {
        return CommonResult.success(flashPromotionSessionService.detail(id));
    }

    @Operation(summary = "获取全部")
    @GetMapping("/list")
    public CommonResult<List<SmsFlashPromotionSession>> list() {
        return CommonResult.success(flashPromotionSessionService.list());
    }

    @Operation(summary = "获取全部可选场次以及数量")
    @GetMapping("/selectList")
    public CommonResult<List<SmsFlashPromotionSessionDetail>> selectList(Long flashPromotionId) {
        List<SmsFlashPromotionSessionDetail> promotionSessionList = flashPromotionSessionService.selectList(flashPromotionId);
        return CommonResult.success(promotionSessionList);
    }
}
